package com.ruoyi.controller;

import com.ruoyi.service.DashScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/dashscope")
public class DashScopeController {

    @Autowired
    private DashScopeService dashScopeService;

    @PostMapping("/generate-background")
    public ResponseEntity<Map<String, Object>> generateBackground(@RequestBody Map<String, String> request) {
        System.out.println("进行中");
        String baseImageUrl = request.get("baseImageUrl");
        String refImageUrl = request.get("refImageUrl");
        String refPrompt = request.get("refPrompt");

        String taskId = dashScopeService.generateBackground(baseImageUrl, refImageUrl, refPrompt);

        Map<String, Object> response = new HashMap<>();
        response.put("taskId", taskId);
        response.put("message", "背景生成任务已提交，请使用任务ID查询结果");

        return ResponseEntity.ok(response);
    }

    @GetMapping("/task/{taskId}")
    public ResponseEntity<String> getTaskResult(@PathVariable String taskId) {
        String result = dashScopeService.queryTaskResult(taskId);
        return ResponseEntity.ok(result);
    }
}
